<script>
  $('#modal-form-submit').click(function(e){
    e.preventDefault();

    var object = $('#<%= "new_#{related.model_name.to_s.downcase}" %>');
    var data = object.serialize();
    var url = object.attr('action');

    $.ajax({
      url: url,
      type: 'POST',
      data: data,
      success: function(data) {
        $('.modal-body').html(data);
        var option = new Option($("#_label").attr("value"), $("#_id").attr("value"), true, true);
        parent.$("#<%= attribute_id %>").prepend(option);
        $("#modal-from-dom-<%= attribute_id %>").modal('hide');
      },
      error: function(request, status, error) {
        $('.modal-body').html(request.responseText);
      }
    })

  });
</script>
